<template>
  <div class="about">
    <van-nav-bar title="管理员视频上传" />
    <van-progress :percentage="0" />
    <!-- <van-button type="primary" icon="plus">新增视频</van-button> -->

    <!-- 文件上传视频输入框 -->
    <div class="container">
      <van-uploader
        accept="video/*"
        :before-read="handlefilechange"
        :file-list="fileList"
         :after-read="handlefilechange"
        class="upload-file-uploader"
        ref="fileUpload"
      />
      <div class="updatavideo">上传视频</div>
      <!-- <input
        type="file"
        ref="fileinput"
        multiple
        accept="video/*"
        @change="handlefilechange"
      /> -->
    </div>
     <div>
      <router-link to="/userVideo">进播放页面</router-link>
     </div>
    <van-card
      :desc="item.title"
      title="视频1"
      v-for="item in adminvideoinfo"
      :key="item.labelId"
    >
      <div slot="footer">
        {{ item.title }}
        <van-button size="mini" @click="deledevideo(item.labelId)"
          >删除</van-button
        >
      </div>
    </van-card>
    <!-- 上传文件 -->
    <div class="updatefilebox">
    <van-uploader v-model="fileList" :after-read="afterRead" >
      <template #preview-cover="{ file }">
        <div class="preview-cover van-ellipsis">{{ file.file }}</div>
      </template>
    </van-uploader>
    <div class="updatefile">上传文件</div>
    </div>

  </div>
</template>

<script>
import { uploadfile, getvideodata } from '../api/index'
export default {
  name: 'adminabout',
  data () {
    return {
      updatemsg: '',
      adminvideoinfo: [],
      fileList: [],
      // 获取图片信息列表
      imgtextlinst: []
      // list: 'hello'
    }
  },
  mounted () {
    // this.$bus.$emit('test', '测试')
  },
  methods: {
    handlefilechange (event) {
      // console.log(event, "////");
      const selectfile = event
      // const selectfile = event.target.files[0]
      const formData = new FormData()
      formData.append('file', selectfile)
      this.uploadfile(formData)
    },

    // 点击添加视频
    async uploadfile (selectfile) {
      const result = await uploadfile(selectfile)
      console.log(result, '222')
      if (result.msg === '上传成功') {
        this.updatemsg = result.msg
        this.$dialog.alert({
          message: this.updatemsg
        })
      }
      this.getvideodatainfo()
    },

    // 获取数据信息进行展示
    async getvideodatainfo () {
      const result = await getvideodata()
      this.adminvideoinfo = result.data
    },

    // 上传文本图片函数
    async afterRead (file) {
      // // 此时将文件上传至服务器
      // new一个formdata对象
      const formData = new FormData()
      // 这里需要传递的是整个对象而不仅仅是文件名
      formData.append('file', file.file)
      this.$store.dispatch('updatagetimgtext', formData)
      // const result = await getimgtext(formData)

      // if (result.msg === '解析成功') {
      //   this.$dialog.alert({
      //     message: '上传成功啦'
      //   })
      // }
      // this.imgtextlinst = result.data
    }

    // 删除视频
    // async deledevideo (deledeid) {
    //   const dele = await deletevideo(deledeid)
    //   if (dele.code === 200) {
    //     return 'ok'
    //   } else {
    //     return Promise.reject(new Error('faile'))
    //   }
    // }
  }
}
</script>
<style scoped lang="less">
.van-nav-bar {
  background: #007bff;
}

/deep/ .van-nav-bar__title {
  color: white;
}

.about {
  .container {
    margin-top: 30px;
    margin-bottom: 20px;
    width: 300px;
    height: 140px;
    border: 1px solid #007bff;
    margin-left: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
     flex-direction: column;
    input {
      font-size: 15px;
    }
    input::file-selector-button {
      border: 1px solid #007bff;

      font-size: 15px;
      border-radius: 5px;
      background-color: azure;
      height: 100px;
      width: 100px;
      margin-top: 20px;
      margin-left: 100px;
      text-align: center;
    }
  }
  .updatafile {
    background-color:#f7f8fa ;
  }
  .updatavideo {
    font-size: 18px;
  }
}
::v-deep .van-dialog {
  left: 40%;
}
.van-card {
  // background-color: pink;
  border-radius: 5px;
  margin: 5px 5px;
  border: 1px solid #333;
  .van-multi-ellipsis--l2 {
    font-size: 19px;
  }
  .van-card__desc {
    font-size: 19px;
    margin: 10px;
  }
}
// 文件上传样式
.preview-cover {
  position: absolute;
  bottom: 0;
  box-sizing: border-box;
  width: 100%;
  padding: 4px;
  color: #fff;
  font-size: 12px;
  text-align: center;
  background: rgba(0, 0, 0, 0.3);
}
.van-uploader {
  margin: 20px 106px;
  border: 1px solid #007bff;
  width: auto;
  height: 80px;
  text-align: center;
  background-color: #f7f8fa;
}
.updatefilebox {
    margin-top: 30px;
     width: 300px;
    height: 150px;
    border: 1px solid #007bff;
    margin-left: 36px;

 .updatefile {
margin:  0 110px;
  display: inline;
  font-size: 19px;
}
}

</style>
